<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE html>
<html>
<head>
    <%@include file="../../../resources/inc/head.jsp" %>
</head>
<body>

<div class="layui-fluid">
    <expect-x:tip tipMessage="标识“*”的选项为必填项，其余为选填项。;请按提示信息填写每一个字段"/>

    <div class="layui-card">
        <div class="layui-form layui-card-header layuiadmin-card-header-auto option-bar">
            <div class="layui-collapse ">
                <div class="layui-colla-item">
                    <h2 class="layui-colla-title">展开搜索</h2>
                    <div class="layui-colla-content">
                        <div class="layui-form-item">
                            <div class="layui-inline">
                                <input type="text" name="merchantNo" placeholder="输入商户号" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-inline">
                                <button  class="layui-btn" lay-submit lay-filter="Type-serch">
                                    搜索
                                </button>
                            </div>
                        </div>
                    </div>

                </div>
            </div>
        </div>

        <div class="layui-card-body">
            <table id="merchantPaymentConfigManage" lay-filter="merchantPaymentConfigManage"></table>
            <%--<script type="text/html" id="optionToolbar">--%>
                <%--<div class="layui-btn-container">--%>
                        <%--<button class="layui-btn layui-btn-sm" lay-event="add">新增</button>--%>
                        <%--<button class="layui-btn layui-btn-danger layui-btn-sm" lay-event="dels"id="dels">批量删除</button>--%>

                <%--</div>--%>
            <%--</script>--%>
            <script type="text/html" id="optionBar">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit">编辑</a>
                    <%--<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>--%>
            </script>
            <script type="text/html" id="gmtModifiedTpl">
                {{#
                var date = new Date();
                date.setTime(d.gmtModified);
                return date.Format("yyyy-MM-dd hh:mm:ss");
                }}
            </script>

            <script type="text/html" id="isDisabledTpl">
                <input type="checkbox" name="state" value="{{d.id}}" title="禁用" lay-filter="isDisabledFilter" {{
                       d.state== 1 ? 'checked' : '' }}>
            </script>
            <script type="text/html" id="icon">
                <div><img src="{{d.icon==null?'<%=basePath%>resources/images/noImage.jpg':d.icon}}" style="height: 28px" class="layui-table-link"></div>
            </script>
            <script type="text/html" id="merchantNo">
                {{d.merchantUser.company==null?'':d.merchantUser.company}}
            </script>
            <script type="text/html" id="agentNo">
                {{d.merchantApplication.name==null?'':d.merchantApplication.name}}
            </script>
        </div>
    </div>
</div>

<%@include file="../../../resources/inc/footer.jsp" %>
<script>
    layui.config({
        base: '<%=basePath%>resources/lib/layuiAdmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'table'], function () {
        var $ = layui.$
            , form = layui.form
            , table = layui.table;
        table.render({
            elem: '#merchantPaymentConfigManage',
            url: '<%=basePath%>manager/merchantPaymentConfig/page.html',
            cols: [[
                {type: 'checkbox',fixed:'left'},
                {field: 'id', width: 50, title: 'ID', sort: true}
                , {field: 'merchantNo', width: 170, title: '商户号'}
                , {field: 'appId', width: 170, title: 'APP_ID'}
                , {field: 'mchId', width: 150, title: 'MCH_ID'}
                , {field: 'privateKey', width: 150, title: '私钥'}
                , {field: 'publicKey', width: 150, title: '公钥'}
                , {field: 'signType', width: 150, title: '签名方式'}
                , {field: 'gateUrl', width: 150, title: '配置网关'}
                , {field: 'payWay', width: 150, title: '支付方式'}
                , {title: '更新时间', width: 130, sort: true, templet: "#gmtModifiedTpl"}
                , {title: "操作", width: 150, align: "center", fixed: "right", toolbar: "#optionBar"}
            ]],
            page: !0,
            limit: 10,
            height: "full-130",
            text: {none:"暂无可显示数据"},
            response: {
                statusCode: 200
            }
        });

        table.on('toolbar(merchantPaymentConfigManage)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
                case 'add':
                    var diglog=new UtilClass.LayerDialog({
                        title: '添加商户支付配置'
                        ,content:'<%=basePath%>manager/merchantPaymentConfig/create.html',
                    });
                    diglog.layerShow();
                    break;

                case 'dels':
                    var data = checkStatus.data;

                    var List=JSON.stringify(data);
                    var jsList =JSON.parse(List);
                    if(jsList[0]==null){
                        layer.msg('请选中至少一行');

                    }else{


                        var chars=new Array();
                        for(var  li in jsList){
                            chars[li]=jsList[li].id;
                        }
                        var str="";
                        for( var i=0;i<chars.length;i++){
                            if(i==chars.length-1){
                                str+=chars[i];
                            }
                            else{str=str+chars[i]+",";}

                        }
                        layer.load(2);
                        $.ajax({
                            type: "get",
                            url: "<%=basePath%>manager/merchantPaymentConfig/delete/"+str+".html",
                            success: function(data) {
                                layer.closeAll("loading");
                                data=JSON.parse(data);


                                if(data.success){
                                    layer.msg("删除成功");
                                    table.reload('merchantPaymentConfigManage');

                                }else{
                                    layer.msg(data.message, {icon: 5});
                                }
                            }
                        });
                        break;}
            };
        });
        table.on("tool(merchantPaymentConfigManage)", function (e){
            console.log(e.data);
            if ("del" === e.event){
                layer.confirm("真的删除行么", function (t) {
                    layer.close(t);

                    var List=JSON.stringify(e.data);
                    var jsList =JSON.parse(List);
                    var ids=jsList.id;

                    layer.load(2);
                    $.ajax({
                        type: "get",
                        url: "<%=basePath%>manager/merchantPaymentConfig/delete/"+ids+".html",
                        success: function(data) {
                            layer.closeAll("loading");
                            data=JSON.parse(data);

                            if(data.success){
                                table.reload('merchantPaymentConfigManage');

                            }else{
                                layer.msg(data.message, {icon: 5});
                            }
                        }
                    });

                })
            }else if ("edit" === e.event) {
                var diglog=new UtilClass.LayerDialog({
                    title:"编辑商户支付配置"
                    ,content: "<%=basePath%>manager/merchantPaymentConfig/update/"+e.data.id+".html",
                });
                diglog.layerShow();
            }
        });

        //监听搜索
        form.on('submit(Type-serch)', function (data) {
            var field = data.field;
            $(".layui-laypage-skip").find("input").val("1");
            $(".layui-laypage-btn").click();

            table.reload('merchantPaymentConfigManage', {
                where: {merchantNo:field.merchantNo}
            });
        });


    });
    function edit(e) {

    }

</script>
</body>
</html>

